package org.lex.collection;

import java.util.AbstractSet;
import java.util.IdentityHashMap;
import java.util.Iterator;
import java.util.Set;

public class IdentityHashSet<E> extends AbstractSet<E> implements Set<E> {
	private static final Object value = new Object();
	private IdentityHashMap<E, Object> map = new IdentityHashMap<E, Object>();

	@Override
	public boolean add(E e) {
		return null != map.put(e, value);
	}

	@Override
	public void clear() {
		map.clear();
	}

	@Override
	public boolean contains(Object o) {
		return map.containsKey(o);
	}

	@Override
	public boolean isEmpty() {
		return map.isEmpty();
	}

	@Override
	public Iterator<E> iterator() {
		return map.keySet().iterator();
	}

	@Override
	public boolean remove(Object o) {
		return null != map.remove(o);
	}

	@Override
	public int size() {
		return map.size();
	}
}
